#include "jgeneralenglishinputpanel.h"
#include "ui_jgeneralenglishinputpanel.h"
#include "inputmethod/jabstractinputpanel_p.h"
#include "widgets/jvkbutton.h"
#include <QTECore/QTEGlobal>

namespace QTE
{

InputPanel_register(JGeneralEnglishInputPanel, LGG_GeneralEnglish);

class Q_DECL_HIDDEN JGeneralEnglishInputPanelPrivate : public JAbstractInputPanelPrivate
{
public:
	~JGeneralEnglishInputPanelPrivate() override;
	void init(JAbstractInputPanel *q_ptr) override;

public:
	void setLowercaseLetter();
	void setCapitalize();

public:
	Ui::JGeneralEnglishInputPanel *ui;
};

JGeneralEnglishInputPanelPrivate::~JGeneralEnglishInputPanelPrivate()
{
	delete ui;
}

void JGeneralEnglishInputPanelPrivate::init(JAbstractInputPanel *q_ptr)
{
	JAbstractInputPanelPrivate::init(q_ptr);
	ui = new Ui::JGeneralEnglishInputPanel();
	ui->setupUi(J_RCT(JGeneralEnglishInputPanel*, q_ptr));
	ui->horizontalLayout_4->insertWidget(ui->horizontalLayout_4->count() - 1, m_backSpaceButton);
}

void JGeneralEnglishInputPanelPrivate::setLowercaseLetter()
{
	ui->tb_capslock->setIcon(QIcon(":/picture/noCapslock.png"));
	ui->j_tb_a->setText("a");
	ui->j_tb_b->setText("b");
	ui->j_tb_c->setText("c");
	ui->j_tb_d->setText("d");
	ui->j_tb_e->setText("e");
	ui->j_tb_f->setText("f");
	ui->j_tb_g->setText("g");
	ui->j_tb_h->setText("h");
	ui->j_tb_i->setText("i");
	ui->j_tb_j->setText("j");
	ui->j_tb_k->setText("k");
	ui->j_tb_l->setText("l");
	ui->j_tb_m->setText("m");
	ui->j_tb_n->setText("n");
	ui->j_tb_o->setText("o");
	ui->j_tb_p->setText("p");
	ui->j_tb_q->setText("q");
	ui->j_tb_r->setText("r");
	ui->j_tb_s->setText("s");
	ui->j_tb_t->setText("t");
	ui->j_tb_u->setText("u");
	ui->j_tb_v->setText("v");
	ui->j_tb_w->setText("w");
	ui->j_tb_x->setText("x");
	ui->j_tb_y->setText("y");
	ui->j_tb_z->setText("z");
}

void JGeneralEnglishInputPanelPrivate::setCapitalize()
{
	ui->tb_capslock->setIcon(QIcon(":/picture/capslock.png"));
	ui->j_tb_a->setText("A");
	ui->j_tb_b->setText("B");
	ui->j_tb_c->setText("C");
	ui->j_tb_d->setText("D");
	ui->j_tb_e->setText("E");
	ui->j_tb_f->setText("F");
	ui->j_tb_g->setText("G");
	ui->j_tb_h->setText("H");
	ui->j_tb_i->setText("I");
	ui->j_tb_j->setText("J");
	ui->j_tb_k->setText("K");
	ui->j_tb_l->setText("L");
	ui->j_tb_m->setText("M");
	ui->j_tb_n->setText("N");
	ui->j_tb_o->setText("O");
	ui->j_tb_p->setText("P");
	ui->j_tb_q->setText("Q");
	ui->j_tb_r->setText("R");
	ui->j_tb_s->setText("S");
	ui->j_tb_t->setText("T");
	ui->j_tb_u->setText("U");
	ui->j_tb_v->setText("V");
	ui->j_tb_w->setText("W");
	ui->j_tb_x->setText("X");
	ui->j_tb_y->setText("Y");
	ui->j_tb_z->setText("Z");
}

/*------------------------------------------------------------------------------------------------*/

JGeneralEnglishInputPanel::JGeneralEnglishInputPanel(QWidget *parent) :
	JAbstractInputPanel(new JGeneralEnglishInputPanelPrivate(), parent)
{
	Q_D(JGeneralEnglishInputPanel);
	connect(d->ui->tb_capslock, &QToolButton::clicked, this, &JGeneralEnglishInputPanel::on_tb_capslockClicked);
}

JGeneralEnglishInputPanel::~JGeneralEnglishInputPanel()
{

}

void JGeneralEnglishInputPanel::reset()
{
	d_func()->setLowercaseLetter();
}

void JGeneralEnglishInputPanel::on_tb_capslockClicked()
{
	Q_D(JGeneralEnglishInputPanel);

	if( d->ui->j_tb_a->text() == "A" )
		d->setLowercaseLetter();
	else
		d->setCapitalize();
}

} //namespace QTE
